package com.day4;
import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.Scanner;
public class Yibaizhengshu {
    public static void main(String[] args) {
    isTest();
    }
    public static void isSum1(int[] arr){
        int sum=0;
        for (int i = 0; i <arr.length; i++) {
            sum+=arr[i];
        }
        System.out.println("总分:"+sum);
    }//求数组元素之和
    public static void isMax(int[] arr){
        int max=arr[0];
        for (int i = 1; i <arr.length; i++) {
            if (arr[i]>max){
                max=arr[i];
            }
        }
        System.out.println("最大值:"+max);
    }//求数组元素最大值
    public static void isMin(int[] arr){
        int min=arr[0];
        for (int i = 1; i <arr.length; i++) {
            if (arr[i]<min){
                min=arr[i];
            }
        }
        System.out.println("最小值:"+min);
    }//求数组元素最小值
    public static void isAvrege(int[] arr){
        int sum=0;
        for (int i = 0; i <arr.length; i++) {
            sum+=arr[i];
        }
        int avrige=sum/arr.length;
        System.out.println("平均值:"+avrige);
    }
    public static void isTest() { //此处为有参数方法的定义;
        /*int[] ints = new int[]{22,33,44,55};
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数:");
        int a=sc.nextInt();
        int index=-1;
        for (int i = 0; i <ints.length; i++) {
            if (ints[i]==a){
                index=i;
            }
        }
        if (index !=-1){
            System.out.println("数据找到了,在"+index);
        }else{
            System.out.println("数据不存在");
        }*/
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[5];
        int sum=0,max=0,min=0;
        for (int i = 0; i <arr.length; i++) {
            System.out.println("请输入第"+(i+1)+"个成绩:");
            arr[i]=sc.nextInt();
            if (arr[i]>100 ||arr[i]<0){
                System.out.println("输入成绩错误,请输入正确的成绩");
                i--;
            }
        }
        isSum1(arr);
        isMax(arr);
        isMin(arr);
        isAvrege(arr);
    }
}

